package com.ucar.training.listener;

import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

/**
 * @author XiongMM
 * @date 2019/7/26 15:40
 * @description
 *
 * 这个监听器提供了session参数在新增、修改、删除时的监听，如果在应用层代码中对session参数进行操作：

request.getSession().setAttribute("testContextAttribute", "abc");

request.getSession().setAttribute("testContextAttribute", "def");

request.getSession().removeAttribute("testContextAttribute");
监听器就会有如下输出：

26E7704D5B524C997B34E54021D46E44新增session参数，name:testContextAttribute,value:abc

26E7704D5B524C997B34E54021D46E44修改session参数，name:testContextAttribute,value:abc

26E7704D5B524C997B34E54021D46E44删除session参数，name:testContextAttribute,value:def


 */
public class MyHttpSessionAttributeListener implements HttpSessionAttributeListener {
    @Override
    public void attributeAdded(HttpSessionBindingEvent arg0) {
        System.out.println(arg0.getSession().getId()+"新增session参数，name:"+arg0.getName()+",value:"+arg0.getValue());

    }

    @Override
    public void attributeRemoved(HttpSessionBindingEvent arg0) {
        System.out.println(arg0.getSession().getId()+"删除session参数，name:"+arg0.getName()+",value:"+arg0.getValue());

    }

    @Override
    public void attributeReplaced(HttpSessionBindingEvent arg0) {
        System.out.println(arg0.getSession().getId()+"修改session参数，name:"+arg0.getName()+",value:"+arg0.getValue());

    }

}
